<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8"/>
    <title></title>
    <meta name="renderer" content="webkit"/>
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"/>
    <meta
            name="viewport"
            content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0"
    />
    <link rel="stylesheet" href="/layuiadmin/layui/css/layui.css" media="all"/>
    <link rel="stylesheet" href="/layuiadmin/style/admin.css" media="all"/>
</head>
<body layadmin-themealias="default">
<div class="layui-fluid">
    <div class="layui-row layui-col-space15">
        <div class="layui-col-md12">
            <div class="layui-card">
                <div class="layui-form" wid100="" lay-filter="form">
                <div class="layui-card-body" pad15="">
                    <div class="layui-form-item">
                        <label class="layui-form-label">IP</label>
                        <div class="layui-input-block">
                            <input type="text"
                                   name="ip" value="" placeholder="请输入IP地址..." class="layui-input"
                                   lay-verify="required|ip"
                            />
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">备注</label>
                        <div class="layui-input-block">
                            <input type="text"
                                   name="remark" value="" placeholder="请输入备注..." class="layui-input"
                                   lay-verify="required"
                            />
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <div class="layui-input-block">
                            <button class="layui-btn" lay-submit="" lay-filter="white-add">确认保存</button>
                        </div>
                    </div>
                </div>
                </div>
            </div>
        </div>
    </div>
</div>
</div>

<script src="/layuiadmin/layui/layui.js"></script>
<script src="/assets/cos-js-sdk-v5/cos-js-sdk-v5.min.js"></script>
<script src="/assets/ue/third-party/jquery-1.10.2.js"></script>
<script>

    layui.config({
        base: "/layuiadmin/", //静态资源所在路径
    }).extend({
        index: "lib/index", //主入口模块
    }).use(['index', "form", "laytpl", "admin"], function () {
        var form = layui.form;
        var admin = layui.admin;
        form.verify({
            ip: function (value, item) {
                function isValidIP(ip) {
                    var reg = /^(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])$/
                    return reg.test(ip);
                }

                if (isValidIP(value) === false) {
                    return '请输入正确的IP地址';
                }
            }
        });
        form.on("submit(white-add)", function (obj) {
            var data = obj.field;
            layer.load();
            //提交
            admin.req({
                url: "/admin/white_ip/add_post",
                data: data,
                success: function (res) {
                    if (res.code == 0) {
                        layer.msg(res.msg, { icon: 1 });
                        layer.closeAll("loading");
                        window.parent.location.reload();
                        var index = parent.layer.getFrameIndex(window.name);
                        parent.layer.close(index);
                    } else {
                        layer.closeAll("loading");
                        layer.msg(res.msg, { icon: 5 });
                    }
                },
                done: function () {
                    layer.closeAll("loading");
                },
            });
            return false;
        });
    });


</script>
</body>
</html>
